package lib.bone.access.config.cycle;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * 教学周期 和 科研周期整合在一起
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_workload_cycle")
@ApiModel(value = "工作量周期")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class NepuCycle {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "周期ID",name = "id")
    String id;

    @Column(name = "cycle_name")
    @ApiModelProperty(value = "周期名称",notes = "例如:2021-2022 第一学期")
    String cycleName;

    @ApiModelProperty(value = "父周期ID")
    @Column(name = "parent_id")
    String parentId;

    @ApiModelProperty(value = "周期类型",notes = "现在分配教学周期和科研周期")
    @Column(name = "cycle_type")
    String cycleType;

    @ApiModelProperty("开始日期")
    @Column(name = "start_date")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    Date startDate;

    @ApiModelProperty("结束日期")
    @Column(name = "end_date")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    Date endDate;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuCycle nepuCycle = (NepuCycle) o;
        return id != null && Objects.equals(id, nepuCycle.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
